﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Mono.Nat;

namespace POS
{
    public partial class Testing : DevExpress.XtraEditors.XtraForm
    {
        public Testing()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        private void Testing_Load(object sender, EventArgs e)
        {
            NatUtility.DeviceFound += DeviceFound;
            NatUtility.DeviceLost += DeviceLost;

            NatUtility.StartDiscovery();
        }

        private void DeviceFound(object sender, DeviceEventArgs args)
        {
            INatDevice device = args.Device;

            device.CreatePortMap(new Mapping(Protocol.Tcp, 80, 80));
            device.CreatePortMap(new Mapping(Protocol.Udp, 80, 80));

            foreach (Mapping portMap in device.GetAllMappings())
            {
                memoEdit1.Text += "\r\n" + (portMap.ToString());
            }

            memoEdit1.Text += "\n\r" + (device.GetExternalIP().ToString());
        }

        private void DeviceLost(object sender, DeviceEventArgs args)
        {
            INatDevice device = args.Device;

            device.DeletePortMap(new Mapping(Protocol.Tcp, 80, 80));
        }
    }
}